﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace Tradex.Trading {

    /// <summary>
    /// An AccountUpdate is the dynamic description of an account at a given moment in time.
    /// </summary>
    [Serializable()]
    public class AccountUpdate {

        /// <summary>
        /// Constructor taking all arguments.
        /// </summary>
        /// <param name="balance"></param>
        /// <param name="cashOnHand"></param>
        /// <param name="openProfit"></param>
        /// <param name="closedProfit"></param>
        /// <param name="buyMargin"></param>
        /// <param name="sellMargin"></param>
        public AccountUpdate (
            double balance, double cashOnHand,
            double openProfit, double closedProfit,
            double buyMargin, double sellMargin
        ) {
            Timestamp = DateTime.UtcNow;
            Balance = balance;
            CashOnHand = cashOnHand;
            OpenProfit = openProfit;
            ClosedProfit = closedProfit;
            BuyMargin = buyMargin;
            SellMargin = sellMargin;
        }

        /// <summary>
        /// Gets the Timestamp.
        /// </summary>
        public DateTime Timestamp { get; private set; }

        /// <summary>
        /// Gets the balance of the account, including non-cash positions.
        /// </summary>
        public double Balance { get; private set; }

        /// <summary>
        /// Gets the cash on hand value.
        /// </summary>
        public double CashOnHand { get; private set; }

        /// <summary>
        /// Gets the open profit (since the last reet, which normally happen daily at consolidation).
        /// </summary>
        public double OpenProfit { get; private set; }

        /// <summary>
        /// Gets the closed profit (since last reset, which normally happen daily at consolidation).
        /// </summary>
        public double ClosedProfit { get; private set; }

        /// <summary>
        /// Gets the available margin for purchases.
        /// </summary>
        public double BuyMargin { get; private set; }

        /// <summary>
        /// Gets the available margin for sales.
        /// </summary>
        public double SellMargin { get; private set; }

        /// <inheritdoc />
        public override string ToString() {
            return String.Format(
                CultureInfo.InvariantCulture,
                "Balance {0} / Cash {1}; Open {2} Closed {3}; Buy {4} Sell {5}",
                Balance, CashOnHand, OpenProfit, ClosedProfit, BuyMargin, SellMargin
            );
        }

    }

}
